package com.ruoyi.cases.controller;

import com.ruoyi.cases.domain.JlDailyStatistics;
import com.ruoyi.cases.domain.JlTroubleshootingTable;
import com.ruoyi.cases.service.IJlDailyStatisticsService;
import com.ruoyi.cases.utils.excel.ExcelExportToFileUrlComplex;
import com.ruoyi.cases.utils.excel.HexBeanUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 个人日统计Controller
 * 
 * @author ruoyi
 * @date 2024-05-21
 */
@RestController
//@RequestMapping("/cases/statisticsMouth")
public class JlMouthStatisticsController extends BaseController
{
    @Autowired
    private IJlDailyStatisticsService jlDailyStatisticsService;

    /**
     * 查询工区统计
     */
    @PreAuthorize("@ss.hasPermi('cases:statisticsDaily:list')")
    @GetMapping("/list")
    public TableDataInfo list(JlTroubleshootingTable jlTroubleshootingTable)
    {
        startPage();
        List<JlTroubleshootingTable> list = jlDailyStatisticsService.getMouthStatisticsList(jlTroubleshootingTable);
        return getDataTable(list);
    }


    /**
     * 获取个人日统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('cases:statisticsDaily:query')")
    @GetMapping(value = "/getDetail")
    public List<JlDailyStatistics> getDetail(JlDailyStatistics jlDailyStatistics)
    {
        return jlDailyStatisticsService.getDetail(jlDailyStatistics);
    }

    /**
     * 导出病害排查列表
     */
    @PreAuthorize("@ss.hasPermi('cases:statisticsDaily:export')")
    @Log(title = "个人日统计自定义版本", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTest")
    public void exportTest(HttpServletRequest request, HttpServletResponse response, JlDailyStatistics jlDailyStatistics)
    {
        List<JlDailyStatistics> list = jlDailyStatisticsService.selectJlDailyStatisticsList(jlDailyStatistics);
        try{
            int xh = 1;
            Map model = new HashMap();
            List<Map<String, Object>> listdata = new ArrayList<>();
            for (JlDailyStatistics val: list) {
                val.setXh(xh);
                Map<String, Object> map = HexBeanUtils.object2Map(val);
                listdata.add(map);
                xh++;
            }
            String name ="xh,statisticsDate,deptName,username,statisticsDetail,ratedCoefficient,quotaStandard,rewardDeductionAmount,assessorName,remark";
            model.put("excelTitleClos", name.split(",").length-1);
            model.put("fileName", "车道巡检明细表");
            model.put("excelTitle", "张三养护工区定额工作完成情况评价表（个人）");
            //[[行号,列号(&分隔),文字(&分隔),合并单元格(起始行,结束行,起始列,结束列)]]
            model.put("names", name.split(","));
            model.put("excelTitleFontSize", "20");
            model.put("titles0",
                    new String[]{"张三养护工区定额工作完成情况评价表（个人）"});
            model.put("titles1",
                    new String[]{"序号", "日期", "工区", "姓名", "工作量明细","额定系数","定额标准","奖励/扣除金额","考核人","备注"});
            model.put("titleStarRows", 1);
            model.put("titleRows", 2);
            model.put("list", listdata);
            String columnWidth =
                    "0,15&1,30&2,20&3,20&4,100&5,25&6,25&7,25&8,25&9,50";
            model.put("columnWidth", columnWidth);
            new ExcelExportToFileUrlComplex().buildExcelDocument1(model, request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
